package TAIC.util;

import java.io.File;
import java.io.PrintStream;
import java.util.Scanner;

public class SelectRows {

	/**
	 * @param args
	 * This program is used to select sepecifc a K in the K-Base Experiments
	 * E.x: ~ config.txt exp61_ 41  
	 */
	public static void main(String[] args) throws Exception {
		if ( args.length != 3 ) {
			System.out.println ( "please input the confingFile, the output ExpName and the K you want to choose" ) ; 
			return ; 
		}
		( new SelectRows ()).work ( args ) ; 
	}

	public void work ( String [] args ) throws Exception {
		String outExpPrefix = args [ 1 ] ;
		int K = Integer.valueOf( args[ 2 ] ) ; 
		Scanner scanner = new Scanner ( new File (args[0])) ;
		String prefix = scanner.next() ;
		while ( scanner.hasNext () ) {
			String index = scanner.next () ;
			String fileName  = prefix + index + ".txt" ;
			String outFileName = outExpPrefix + index + ".txt" ;
			
			Scanner innerScanner = new Scanner ( new File ( fileName ) ) ; 
			PrintStream fout = new PrintStream ( new File ( outFileName) ) ;
			
			innerScanner.nextInt() ;  // totalK 
			int totalB = innerScanner.nextInt() ;
			int iter = innerScanner.nextInt () ;
			fout.println ( "2 " + totalB + " " + iter ) ; 
			for ( int i = 0 ; i < totalB; i ++ ){
				for ( int j = 0 ; j < iter ; j ++ ) fout.print ( innerScanner.nextDouble() + "\t" ) ;  
				fout.println () ; 
			}
			
			for ( int k = 1 ; k < K ; k ++ )
				for ( int i = 0 ; i < totalB; i ++ )
					for ( int j = 0 ; j < iter ; j ++ ) innerScanner.nextDouble();  

			for ( int i = 0 ; i < totalB; i ++ ){
				for ( int j = 0 ; j < iter ; j ++ ) fout.print ( innerScanner.nextDouble() + "\t" ) ;  
				fout.println () ; 
			}
			fout.close() ;
			innerScanner.close() ;
		}
	}
	
}
